<!-- Loads initialization file with a couple of variables -->

<%@ include file="../../inc/init.jsp" %>

<html>
	<head>
		<title>
			Graduate Admission System | University of California - San Diego | 
			Discipline Analytics
		</title>
		
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/main.css">
		<script type="text/javascript" src="http://www.google.com/jsapi"></script>
		
    	<script type="text/javascript">
      		google.load('visualization', '1', {packages: ['corechart']});
    	</script>
    	
    	<script type="text/javascript">
      		function drawVisualization() {
        	// Create and populate the data table.
        	var data = new google.visualization.DataTable();
        	data.addColumn('string', 'Discipline');
        	data.addColumn('number', 'Applicants');
        	data.addRows(<%= Applications.visualizeDisciplines() %>);
      
        	// Create and draw the visualization.
        	new google.visualization.PieChart(document.getElementById('visualization')).
	            draw(data, {title:"Majors of Applicants", backgroundColor:'transparent'});
      	}
      	google.setOnLoadCallback(drawVisualization);
    	</script>
	</head>
	<body>
		<div class="header-top"></div>
		<div class="header">
			<a href="<%= BASE %>admin/index.jsp"><img src="<%= BASE %>img/logo.png"></a>
		</div>
		<div class="content">
		
		<table>
		<tr><td><a href="<%= BASE %>admin/index.jsp">
			<img src="<%= BASE %>img/home.png"></a>&nbsp;&nbsp;
			</td>
			<td><span style="color: #515151;">You are logged in as: <b><%= request.getRemoteUser() %></b></span>&nbsp;</td>
			<td><a href="<%= BASE %>logout.jsp?page=admin">
				<img src="<%= BASE %>img/logout.png"></a>
			</td>
		</tr>
		</table><br>
		
		<%
			ArrayList<HashMap<String, String>> al = new ArrayList<HashMap<String, String>>();
			HashMap<String, String> hm = new HashMap<String, String>();
			
			/** Get all disciplines and the number of applicants who have them and display it **/
			
			al = Applications.getDisciplines();
			
			out.print("<div style=\"position: relative; float: left;\">" +
		  		  	  "<table class=\"border\"><tr><th>Discipline</th><th>Amount</th></tr>");
			
			for(int i = 0; i < al.size(); i++)
			{
				hm = al.get(i);
				
				/** Deside whether row is odd or even to paint it gray or white **/
				
				if(i%2 == 0)
				{
					out.print("<tr class=\"evenHover\"><td>" + hm.get("discipline") + "</td>");
				}
				else
				{
					out.print("<tr class=\"oddHover\"><td>" + hm.get("discipline") + "</td>");
				}
				
				if(hm.get("count").equals("0"))
				{
					out.print("<td>0</td></tr>");
				}
				else
				{
					out.print("<td><a href=\"applications.jsp?display=discipline&id=" + hm.get("id") + "\">");
					out.print(hm.get("count") + "</a></td></tr>");
				}
			}
			
			out.print("</table></div>");
			out.print("<div id=\"visualization\" style=\"width: 600px; height: 400px; margin-left: 400px;\"></div>");
			out.print("<div style=\"clear: left;\"></div>");
		%>
		</div>
	</body>
</html>